import 'dart:convert';

import 'package:dali_ng_pera/manager/dnp_plugin_manager.dart';
import 'package:dali_ng_pera/net/dnp_net_manager.dart';
import 'package:dio/dio.dart' as dio;
import 'package:get/get.dart';

import 'model/dnp_order_list_info_model.dart';
import 'model/dnp_order_list_model.dart';

class DnpOrderInProgressController extends GetxController {
  final orderList = <DnpOrderListModel>[].obs;

  void onRequestData(String state) {
    DnpPluginManager().showLoading();
    DnpNetManager()
        .post("/haseye/heis", data: dio.FormData.fromMap({'state': "$state"}))
        .then((value) {
      DnpPluginManager().hideLoading();
      if (value.success) {
        try {
          DnpOrderListInfoModel model =
              DnpOrderListInfoModel.fromJson(value.close);
          orderList.value = model.syllables ?? [];
        } catch (e) {
          DnpPluginManager().showToast(e.toString());
        }
      } else {
        DnpPluginManager().showToast(value.kurios ?? "");
      }
    });
  }
}
